package ilender.util;

import java.io.*;
import java.util.Properties;

/**
 * Tools for handling .properties files.
 */
public class PropertiesTools{
	/*Instantiation Guard*/private PropertiesTools(){}

	/**Load a properties file from app/WEB-INF/classes/*/
	private static Properties loadPropertiesFile(String fileBaseName){
		Properties props=new Properties();
		InputStream stream=PropertiesTools.class.getClassLoader().getResourceAsStream(String.format("%s.properties",fileBaseName));
		if(null==stream)
			throw new RuntimeException(String.format("Unable to find properties file for %s",fileBaseName));
		try{
			props.load(stream);
		}catch(IOException e){
			throw new RuntimeException(String.format("Unable to load properties file for %s",fileBaseName));
		}
		return props;
	}

	/**Load facebook-app.properties*/
	public static Properties fetchFacebookProperties(){
		return loadPropertiesFile("facebook-app");
	}

	/**Load database.properties*/
	public static Properties fetchDatabaseProperties(){
		return loadPropertiesFile("database");
	}
}
